package com.hx.strategy.pay.payport;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Huathy
 * @date 2021-08-31 21:49
 * @description
 */
public class PayStrategy {
    public static final String ALI_PAY = "alipay";
    public static final String WX_PAY = "wxpay";
    public static final String JD_PAY = "jdpay";
    public static final String DEFAULT_PAY = ALI_PAY;

    private static Map<String, Payment> payments = new HashMap<>();
    static {
        payments.put(ALI_PAY,new AliPay());
        payments.put(JD_PAY,new JDPay());
        payments.put(WX_PAY,new WxPay());
    }

    /**
     * 通过统一入口实现动态策略
     * @param key
     * @return
     */
    public static Payment get(String key){
        if(payments.containsKey(key)){
            return payments.get(key);
        }
        return payments.get(DEFAULT_PAY);
    }

}
